package com.link.base.base.coupons.service;

import com.link.base.base.accnt.dao.mybatis.mapper.AccountMapper;
import com.link.base.base.coupons.dao.mybatis.mapper.CollectRecordMapper;
import com.link.base.base.coupons.dao.mybatis.mapper.ProCouponsMapper;
import com.link.base.base.coupons.model.CollectRecord;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>优惠券-优惠券领取记录</p>
 * @author 汪大伟
 * @date 2018/6/8
 */

@Service
public class CollectRecordServiceImpl extends BasicServiceImpl<CollectRecord> implements CollectRecordService {

    @Resource
    private CollectRecordMapper collectRecordMapper;

    @Resource
    private BrandSeriesService brandSeriesService;


    @Resource
    private AccountMapper accountMapper;
    @Resource
    private ProCouponsMapper proCouponsMapper;


    @Override
    public BasicMapper<CollectRecord> getBasicMapper() {
        return collectRecordMapper;
    }


    /**
     * @author 汪大伟
     * @param entity
     * @return 优惠卷领取记录列表
     * @date 2018/6/8
     * @exception Exception
     * <p>Description app端可用优惠列表筛选</p>
     */
    @Override
    public List<CollectRecord> queryOrderByExamplePage(CollectRecord entity) throws Exception {
        return collectRecordMapper.queryOrderByExamplePage(entity);
    }

    /**
     * 查询指定红包记录数量
     *
     * @param collectRecord
     * @return Integer 查询总条数
     * @throws Exception
     */
    @Override
    public Integer queryByCollect(CollectRecord collectRecord) throws Exception {
        return collectRecordMapper.queryByCollect(collectRecord);
    }

    /**
     * 批量更新已领取优惠券的微信code
     *
     * @param collectRecords 优惠券列表
     * @throws Exception 异常
     * @author KuangRuifeng
     * @date 2018年12月4日
     */
    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void updWeChatCodes(List<CollectRecord> collectRecords) throws Exception {
        for (CollectRecord collectRecord : collectRecords) {
            CollectRecord cr = new CollectRecord();
            Long id = collectRecord.getId();
            String wechatCode = collectRecord.getWechatCode();
            cr.setId(id);
            cr = this.queryById(cr);
            cr.setWechatCode(wechatCode);
            this.update(cr);
        }
    }

    /**
     * 更新优惠券查看状态
     * @author KuangRuifeng
     * @date 2018年12月13日
     * @throws Exception 异常
     */
    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void updateNoticed(CollectRecord collectRecord) throws Exception {
        collectRecordMapper.updateNoticed(collectRecord);
    }

    @Override
    public void collectRecordUpdateByInterface(CollectRecord collectRecord) throws Exception {
        collectRecordMapper.collectRecordUpdateByInterface(collectRecord);
    }

    /**
     * 查询优惠券领取记录监控列表
     *
     * @param record
     * @return
     * @throws Exception
     */
    @Override
    public List<CollectRecord> queryListPage(CollectRecord record) throws Exception {
        return collectRecordMapper.queryListPage(record);
    }

    /**
     * 查询优惠券领取记录监控详情
     *
     * @param record
     * @return
     * @throws Exception
     */
    @Override
    public CollectRecord queryDetailById(CollectRecord record) throws Exception {
        return collectRecordMapper.queryDetailById(record);
    }

}
